<?php
function getSize( &$_templatessize )
{
				if ( $_templatessize < 1024 )
				{
								return $_templatessize." Byte";
				}
				if ( 1024 <= $_templatessize && $_templatessize < 1048576 )
				{
								return number_format( $_templatessize / 1024, 3 )." KB";
				}
				if ( 1048576 <= $_templatessize && $_templatessize < 1073741824 )
				{
								return number_format( $_templatessize / 1024 * 1024, 3 )." M";
				}
				if ( 1073741824 <= $_templatessize )
				{
								return number_format( $_templatessize / 1024 * 1024 * 1024, 3 )." G";
				}
}

include( "inc/header.php" );
login_check( );
error_reporting( 0 );
echo "\r\n<body>\r\n";
switch ( $_REQUEST['Action'] )
{
case "edit" :
				if ( !( $fp = fopen( $_GET['editfile'], "rb" ) ) )
				{
								exit( "不能打开文件".$_GET['editfile'] );
				}
				$data = fread( $fp, filesize( $_GET['editfile'] ) );
				echo "<script language=\"javascript\" src=\"inc/js.js\"></script>\r\n<table width=\"98%\" border=\"1\" align=\"center\" cellpadding=\"5\" cellspacing=\"0\" class=\"table\">\r\n  <form action=\"Admin_Templates.php?Action=editsever\" method=\"post\" onSubmit=\"return Validator.Validate(this,3)\">\r\n    <tr>\r\n      <td width=\"15%\" align=\"right\">文件名称：</td>\r\n      <td><input name=\"filename\" type=\"text\" value=\"";
				echo $_GET['file'];
				echo "\" size=\"40\" readonly></td>\r\n    </tr>\r\n    <tr>\r\n      <td colspan=\"2\" align=\"right\"><textarea name=\"htmlcontent\" style=\"width:100%\" rows=\"30\" dataType=\"Require\" msg=\"请填写模版内容\">";
				echo $data;
				echo "</textarea></td>\r\n    </tr>\r\n    <tr>\r\n      <td colspan=\"2\" align=\"center\"><input name=\"file\" type=\"hidden\" value=\"";
				echo $_GET['editfile'];
				echo "\"><input type=\"submit\" name=\"Submit_add\" value=\"修改模板\" /></td>\r\n    </tr>\r\n  </form>\r\n</table>\r\n\t";
				fclose( $fp );
				break;
case "editsever" :
				wfile( $_POST['file'], stripcslashes( $_POST['htmlcontent'] ) );
				addlog( "修改模板".$_POST['filename'], $_SESSION['user_name'] );
				admin_showerr( "<li>模板修改成功</li>", "Admin_Templates.php", 1 );
				break;
default :
				echo "<table width=\"98%\" border=\"1\" align=\"center\" cellpadding=\"5\" cellspacing=\"0\" class=\"table\">\r\n  <tr>\r\n    <td colspan=\"6\"><strong>模板编辑</strong></td>\r\n  </tr>\r\n  <tr align=\"center\">\r\n    <td><strong>文件名</strong></td>\r\n    <td width=\"20%\"><strong>修改时间</strong></td>\r\n    <td width=\"20%\"><strong>文件大小</strong></td>\r\n    <td width=\"12%\"><strong>操作</strong></td>\r\n  </tr>\r\n";
				$CurrentPath = $_GET['path'] ? $_GET['path'] : false;
				if ( $CurrentPath === false )
				{
								$CurrentPath = "../templates/$skindir";
				}
				$fso = @opendir( $CurrentPath );
				while ( false !== ( $file = @readdir( $fso ) ) )
				{
								$fullpath = "{$CurrentPath}/{$file}";
								$is_dir = @is_dir( $fullpath );
								if ( $is_dir == "1" )
								{
												if ( $file != ".." && $file != "." )
												{
																echo "<tr onmouseover=\"this.bgColor='#D3EDFC'\" onmouseout=\"this.bgColor='#eff7fd'\">\n";
																echo "  <td colspan=\"4\"><img src=\"images/dir.gif\"> <a href=\"?path=".$CurrentPath."/".$file.( "\">".$file."</a></td>\n" );
																echo "</tr>\n";
												}
												else if ( !( $file == ".." ) && !( realpath( $CurrentPath."/".$file ) == realpath( "../templates/default" ) ) )
												{
																echo "<tr>\n";
																echo "<td colspan=\"4\"><img src=\"images/dir2.gif\"> <a href=\"Admin_Settings.php\">设置模板存放目录</a></td>";
																echo "</tr>\n";
												}
								}
				}
				@closedir( $fso );
				$fso = @opendir( $CurrentPath );
				while ( $file = @readdir( $fso ) )
				{
								$fullpath = "{$CurrentPath}/{$file}";
								$is_dir = @is_dir( $fullpath );
								if ( $is_dir == "0" )
								{
												$size = @filesize( "{$CurrentPath}/{$file}" );
												$size = @getsize( $size );
												$lastsave = @date( "Y-n-d H:i:s", @filemtime( "{$CurrentPath}/{$file}" ) );
												echo "<tr onmouseover=\"this.bgColor='#D3EDFC'\" onmouseout=\"this.bgColor='#eff7fd'\">\n";
												echo "<td>◇ ".$file."</td>\n";
												echo "<td align=\"center\">".$lastsave."</td>\n";
												echo "<td align=\"center\">".$size."</td>\n";
												$file_types = explode( ".", $file );
												$file_type = $file_types[count( $file_types ) - 1];
												if ( strtolower( $file_type ) != "jpg" & strtolower( $file_type ) != "gif" & strtolower( $file_type ) != "bmp" & strtolower( $file_type ) != "png" )
												{
																echo "<td align=\"center\"><a href=\"?editfile=".$CurrentPath."/".$file.( "&Action=edit&file=".$file."\">编辑</a></td>\n" );
												}
												else
												{
																echo "<td align=\"center\"><a href=\"".$CurrentPath."/".$file."\" target=\"_blank\">观看</a></td>\n";
												}
												echo "</tr>\n";
								}
				}
				@closedir( $fso );
}
echo "</table>\r\n</body>\r\n</html>\r\n";
?>
